package com.xxc.web.controller;

import com.xxc.domain.Student;
import com.xxc.service.StudentService;
import com.xxc.vo.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/student")
    public ResultInfo findAll() {
        List<Student> studentList = studentService.findAll();
        return ResultInfo.success(studentList);
    }

    @PostMapping("/student")
    public ResultInfo save(@RequestBody Student student) {
        studentService.save(student);
        return ResultInfo.success(null);
    }

    @PutMapping("/student")
    public ResultInfo update(@RequestBody Student student) {
        studentService.update(student);
        return ResultInfo.success(null);
    }

    @DeleteMapping("/student/{number}")
    public ResultInfo delete(@PathVariable("number") String number) {
        studentService.delete(number);
        return ResultInfo.success(number);
    }

    @GetMapping("/student/{number}")
    public ResultInfo findById(@PathVariable("number") String number) {
        Student student = studentService.findById(number);
        return ResultInfo.success(student);
    }
}
